<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Deal extends CI_Controller {


	function __construct()
    {     	
    	parent::__construct();
		$this->load->model('category'); 
		$this->load->model('user'); 
		$this->load->model('adeal'); 
		$this->load->model('comment'); 
    }


    public function index() {	
    	$data["categories"] = $this->category->getPageCategories();
		$data["session_id"] = $this->session->userdata('id');
		$data["session_name"] = $this->session->userdata('name');

		$this->load->view('deal.php', $data);
	}

	public function id() {
		$data["categories"] = $this->category->getPageCategories();
		$data["session_id"] = $this->session->userdata('id');
		$id = $this->session->userdata('id');
		$data["session_name"] = $this->session->userdata('name');
		$data["avatar"] = $this->user->getUserById($id);
		
		$row = $this->adeal->getRowById(func_get_arg(0));
		$data["comments"] = $this->comment->getCommentsByDealId(func_get_arg(0));
		$data["adeal"] = $row[0];
		$data["adealimages"] = $this->adeal->getADealImages(func_get_arg(0));
		$this->load->view('view_deal.php', $data);
	}

	public function comment() {
		$param = func_get_arg(0);
		$this->comment->addComment($_POST['text'], $param, $this->session->userdata('name'), $this->session->userdata('id'), $_POST['avatar']);
		header("Location: /wow/deal/id/".$param);
	}
}